package com.evol.controller;

import com.evol.domain.AjaxResult;
import com.evol.domain.frp.UserInfo;
import com.evol.domain.vo.UpdUserVo;
import com.evol.domain.vo.UserVo;
import com.evol.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author EvOL
 * @description
 * @date 2024-06-03 09:20
 **/
@Controller
public class UserController extends BaseController{
    @Autowired
    private TokenService tokenService;
    @GetMapping("/tokens")
    @ResponseBody
    public AjaxResult tokens(String user,String token,String comment,Integer page,Integer limit){
        return success(tokenService.getUsers(user,token,comment,page,limit)).put("count",tokenService.getTokenSize());
    }
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult add(@RequestBody UserInfo info){
        return tokenService.addUserinfo(info);
    }
    @PostMapping("/update")
    @ResponseBody
    public AjaxResult update(@RequestBody UpdUserVo user){
        tokenService.updUserinfo(user.getAfter(),user.getBefore());
        return success();
    }
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(@RequestBody UserVo user){
        for(UserInfo info:user.getUsers()){
            tokenService.delUserinfo(info.getUser());
        }
        return success();
    }

    @PostMapping("/enable")
    @ResponseBody
    public AjaxResult enable(@RequestBody UserVo user){
        for(UserInfo info:user.getUsers()){
            tokenService.updEnable(info.getUser(),true);
        }
        return success();
    }
    @PostMapping("/disable")
    @ResponseBody
    public AjaxResult disable(@RequestBody UserVo user){
        for(UserInfo info:user.getUsers()){
            tokenService.updEnable(info.getUser(),false);
        }
        return success();
    }

}
